package chapter11;

import java.awt.*;

public class FileDialogTest {
    Frame frame = new Frame("测试窗口");
    FileDialog fd = new FileDialog(frame, "选择需要打开的文件", FileDialog.LOAD);
    FileDialog fd2 = new FileDialog(frame, "选择保存文件的路径", FileDialog.SAVE);
    Button b1 = new Button("打开文件");
    Button b2 = new Button("保存文件");

    public void init() {
        b1.addActionListener(e -> {
            fd.setVisible(true);
            System.out.println(fd.getDirectory() + fd.getFile());
        });
        b2.addActionListener(e -> {
            fd2.setVisible(true);
            System.out.println(fd2.getDirectory() + fd2.getFile());
        });
        frame.add(b1);
        frame.add(b2, BorderLayout.SOUTH);
        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        new FileDialogTest().init();
    }
}
